﻿<form name="contactForm">
<ion-view title="{{ stateName === 'crm.addContact' ? '新建联系人' : '编辑联系人' }}" hide-nav-bar="true" class="crm-bg">
  
  <!-- <ion-nav-bar class="bar-crm">
    <ion-nav-back-button default-nav-back-button ng-click="goBack()">{{ backTitle() }}</ion-nav-back-button>
  </ion-nav-bar>

  <ion-nav-buttons side="right">
    <button class="button button-clear header-item" ng-click="submit()" ng-disabled="contactForm.$invalid">
      完成
    </button>
  </ion-nav-buttons> -->

  <ion-content class="crm-cm-form">
    <div class="padding"></div>
    
    <div class="list">
      <div class="item item-input item-indent">
        <span class="input-label">姓名<span class="assertive">*</span></span>
        <input type="text" placeholder="请输入姓名" name="name" ng-model="form.name" required>
      </div>

      <div class="item item-input item-select item-indent item-enter">
        <span class="input-label">性别<span class="assertive">*</span></span>
        <select ng-model="form.gender" name="gender">
          <option value="0">男</option>
          <option value="1">女</option>
          <option value="2">未知</option>
        </select>
        <i class="ion-ios-arrow-right"></i>
      </div>
      
      <!-- 联系方式 -->
      <div class="item item-input item-indent" ng-repeat="extend in form.extends">
        <span class="input-label">
          {{ extend.key | crmContactExtendText }}
          <span class="assertive" ng-if="$first">*</span>
        </span>
        <input type="text" placeholder="请输入{{ extend.key | crmContactExtendText }}" name="extend.key" ng-model="extend.value">

        <!-- 地址字段提供定位 -->
        <address-fetcher class="item-note padding-horizontal" ng-model="extend.value" ng-if="extend.key === 'address'">
          <i class="crm-icon36-location" ng-class="{'animated infinite flash': $parent.locationing }"></i>
        </address-fetcher>
        
        <!-- 至少保留一项联系方式 -->
        <span class="item-note padding-horizontal ion-minus-circled assertive"
          ng-if="form.extends.length > 1"
          style="font-size: 20px;"
          ng-click="removeContactWay($index)"
          >
        </span>
      </div>
      
      <div class="item text-center padding-vertical" ng-click="contactWayModal.show()">
        <i class="ion-plus"></i> 添加联系方式
      </div>
    </div>
  
    <div class="list">
      <!-- @Todo: 归属人 -->
      <div class="item item-input item-enter item-indent" ng-click="selectClient()">
        <span class="input-label">关联客户<span class="assertive">*</span></span>
        <div class="input-content">{{ form.client && form.client.fullname }}</div>
        <i class="ion-ios-arrow-right"></i>
        <input type="hidden" ng-model="form.client" name="client" required>
      </div>
      <div class="item item-input item-select item-enter item-indent" ng-repeat="tagGroup in tagGroups">
        <span class="input-label">{{ tagGroup.name }}</span>
        <select ng-options="tag.tagid as tag.name for tag in tagGroup.taglist"
          ng-model="form.tags[tagGroup.groupid]">
        </select>
        <i class="ion-ios-arrow-right"></i>
      </div>
    </div>

    <div class="list" ng-if="!isContactInfoShowed">
      <div class="item text-center  padding-vertical" ng-click="showContactInfo()">
        <i class="crm-icon-chevron-dd"></i>
        填写更多
      </div>
    </div>

    <div class="list" ng-if="isContactInfoShowed">
      <div class="item item-input item-indent item-enter">
        <span class="input-label">生日</span>
        <input type="date" placeholder="请输入联系人生日" name="birthday" ng-model="form.birthday">
        <i class="ion-ios-arrow-right"></i>
      </div>

      <div class="item item-input item-indent">
        <span class="input-label">部门</span>
        <input type="text" placeholder="请输入联系人部门" name="department" ng-model="form.department">
      </div>

      <div class="item item-input item-indent">
        <span class="input-label">职务</span>
        <input type="text" placeholder="请输入联系人职务" name="position" ng-model="form.position">
      </div>
      <!-- @Todo: 编号 -->

      <div class="item item-input item-indent" style="-webkit-align-items: baseline;align-items: baseline;">
        <span class="input-label">备注</span>
        <textarea placeholder="请输入备注" name="remark" ng-model="form.remark" rows="4"></textarea>
      </div>
    </div>

    <div class="padding-horizontal15">
      <button class="button button-block button-positive" ng-click="submit()" ng-disabled="contactForm.$invalid">保存</button>
    </div>
  
    <div class="padding-horizontal15" ng-if="stateName === 'crm.editContact'">
      <button class="button button-block button-light" ng-click="removeContact()" ng-disabled="!form.canDel">
        <span class="assertive" ng-if="form.canDel">删除</span>
        <small ng-if="!form.canDel">无删除权限</small>
      </button>
    </div>

    <div class="padding"></div>
  </ion-content>
</ion-view>
</form>